﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaseNet.Core.Dtos
{
    /// <summary>
    /// layui树菜单dto
    /// </summary>
    public class LayuiTreeDto
    {
        /// <summary>
        /// 节点唯一索引
        /// </summary>
        public string Id { get; set; }
        /// <summary>
        /// 节点标题
        /// </summary>
        public string Title { get; set; }
        /// <summary>
        /// 节点字段名
        /// </summary>
        public string Field { get; set; }
        /// <summary>
        /// 点击节点弹出的url，需开启isJump参数
        /// </summary>
        public string Href { get; set; }
        /// <summary>
        /// 节点是否初始展开
        /// </summary>
        public bool Spread { get; set; }
        /// <summary>
        /// 是否选中
        /// </summary>
        public bool Checked { get; set; }
        /// <summary>
        /// 是否禁用
        /// </summary>
        public bool Disabled { get; set; }
        /// <summary>
        /// 父id
        /// </summary>
        public string PId { get; set; }
        /// <summary>
        /// 子节点
        /// </summary>
        public List<LayuiTreeDto> Children { get; set; }


        /// <summary>
        /// 构建layui树列表
        /// </summary>
        /// <param name="list"></param>
        /// <param name="pId"></param>
        /// <returns></returns>
        public static List<LayuiTreeDto> BuildLayUiTreeList(List<LayuiTreeDto> list, string pId = "0")
        {

            var treeList = new List<LayuiTreeDto>();
            var tempList = list.FindAll(o => o.PId == pId);
            foreach (var item in tempList)
            {
                item.Children = BuildLayUiTreeList(list, item.Id);
                treeList.Add(item);
            }
            return treeList;
        }
    }

}
